package com.liy.supercloud.server.admin.notice;

import de.codecentric.boot.admin.server.domain.entities.Instance;
import de.codecentric.boot.admin.server.domain.entities.InstanceRepository;
import de.codecentric.boot.admin.server.domain.events.InstanceEvent;
import de.codecentric.boot.admin.server.domain.events.InstanceStatusChangedEvent;
import de.codecentric.boot.admin.server.notify.AbstractStatusChangeNotifier;
import de.codecentric.boot.admin.server.notify.LoggingNotifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import reactor.core.publisher.Mono;


public class ExceptionNotifier extends AbstractStatusChangeNotifier {

    private static final Logger LOGGER = LoggerFactory.getLogger(LoggingNotifier.class);

    public ExceptionNotifier(InstanceRepository repository) {
        super(repository);
    }

    protected Mono<Void> doNotify(InstanceEvent event, Instance instance) {
        return Mono.fromRunnable(() -> {
            if (event instanceof InstanceStatusChangedEvent) {
                LOGGER.info("Instance {} ({}) is {}", new Object[]{instance.getRegistration().getName(), event.getInstance(), ((InstanceStatusChangedEvent)event).getStatusInfo().getStatus()});
                String status = ((InstanceStatusChangedEvent)event).getStatusInfo().getStatus();
                byte var4 = -1;
                switch(status.hashCode()) {
                    case -830629437:
                        if (status.equals("OFFLINE")) {
                            var4 = 1;
                        }
                        break;
                    case 2715:
                        if (status.equals("UP")) {
                            var4 = 2;
                        }
                        break;
                    case 2104482:
                        if (status.equals("DOWN")) {
                            var4 = 0;
                        }
                        break;
                    case 433141802:
                        if (status.equals("UNKNOWN")) {
                            var4 = 3;
                        }
                }

                switch(var4) {
                    case 0:
                        System.out.println("发送 健康检查没通过 的通知！");
                        break;
                    case 1:
                        System.out.println("发送 服务离线 的通知！");
                        break;
                    case 2:
                        System.out.println("发送 服务上线 的通知！");
                        break;
                    case 3:
                        System.out.println("发送 服务未知异常 的通知！");
                }
            } else {
                LOGGER.info("Instance {} ({}) {}", new Object[]{instance.getRegistration().getName(), event.getInstance(), event.getType()});
            }

        });
    }
}
